package com.show.pm.operator.information;

import com.show.pm.entity.information.Brand;
import com.show.pm.service.information.BrandService;
import com.show.pm.utils.PageResult;
import com.show.pm.utils.Result;
import com.show.pm.utils.StateCloud;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yp
 * @Date 2020-11-27-9:48
 */
@RestController
@CrossOrigin
@RequestMapping("brand")
//@Slf4j
public class BrandController {

    @Autowired
    private BrandService brandService;
    //路径参数
    @GetMapping("/findPage/{page}/{size}")
    public Result findPage(@PathVariable int page,@PathVariable int size){
        //调用查询分页方法
        PageResult pages = brandService.findPage(page,size);
        //返回参数
        return new Result(true, StateCloud.SUCCESS,"查询成功",pages);
    }

    /**
     * 添加品牌列表
     * @param brand 品牌对象
     * @return void
     */
    @PostMapping("/add")
    public Result addBrand(@RequestBody Brand brand){
        brandService.addBrand(brand);
        return new Result(true, StateCloud.SUCCESS,"添加成功");
    }
    /**
     * 修改品牌列表
     * @param brand 品牌对象
     * @return void
     */
    @PostMapping("/save")
    public Result updateBrand(@RequestBody Brand brand){
        //调用修改的方法
        brandService.update(brand);
        //返回到前台的封装类
        return new Result(true, StateCloud.SUCCESS,"修改成功");
    }
    /**
     * 删除品牌列表
     * @param id 品牌id
     * @return void
     */
    @PostMapping("/deleteBrand/{id}")
    public Result deleteById(@PathVariable Integer id){
        brandService.deleteById(id);
        return new Result(true, StateCloud.SUCCESS,"删除成功");
    }

    /**
     * 根据id查询品牌
     * @param id 品牌id
     * @return brand
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id){
        //根据id查询品牌对象
        Brand serviceById = brandService.findById(id);
        return new Result(true, StateCloud.SUCCESS,"查询成功",serviceById);
    }

}
